package test.java.hashmap;

import test.java.hashmap.bean.Emp;

import java.util.HashMap;
import java.util.Iterator;

/**
 * @author ZCW
 * @createTime 2018/1/19
 * @lastUpdateTime 2018/1/19 ZCW
 */
public class HashMapPutAndGet {

    public static void main(String[] args) {
        HashMapPutAndGet putAndGet = new HashMapPutAndGet();
        putAndGet.test2();
    }

    public void test1() {
        HashMap<Emp, String> map = new HashMap<>();

        Emp e1 = new Emp("e1");
        map.put(e1, e1.name);
        Emp e2 = new Emp("e2");
        map.put(e2, e2.name);
        Emp e3 = new Emp("e3");
        map.put(e3, e3.name);
        Emp e4 = new Emp("e4");
        map.put(e4, e4.name);

        Iterator<String> i = map.values().iterator();
        while (i.hasNext()) {
            System.out.println(i.next());
        }

        System.out.println(map.get(e2));

    }

    public void test2(){
        try {
            Class.forName("test.java.hashmap.bean.Emp");//初始化静态
            getClass().getClassLoader().loadClass("test.java.hashmap.bean.Emp");//未初始化静态
//            test.java.hashmap.bean.Emp emp = new test.java.hashmap.bean.Emp();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Emp {
        String name;

        public Emp(String name) {
            this.name = name;
        }

        @Override
        public int hashCode() {
            return 1111;
        }
    }

}
